<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use app\common\library\Token;
use GeTui\Client;
use GeTui\Template\Notification;
use GeTui\Template\PushInfo;
use xing\push\core\PushFactory;
use xing\push\sdk\geTui\igetui\template\IGtNotificationTemplate;

class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';
    protected $config = null;
    public function initialize()
    {
        parent::initialize();
        $this->config = config('getui.');
    }

    public function index()
    {
        return $this->view->fetch();
    }

    public function news()
    {
        $newslist = [];
        return jsonp(['newslist' => $newslist, 'new' => count($newslist), 'url' => 'https://www.fastadmin.net?ref=news']);
    }

    public function test(){
        $client = new Client([
            'app_id' => 'gOgGqTwgRh7vHyFk0r4yIA',
            'app_key' => 'BhwmxGZyBU9EzbKxYXfuE7',
            'app_secret'=>'zlNnaU8SYd9VLuQJ2RNBY7',
            'master_secret' => 'ZYaWeKKGAL8Y8vTrwiYf9A',
            'logo_url' => 'http://dev.img.ybzg.com/static/app/user/getui_logo.png',
        ]);
//        $ret = $client->single->setClientId('b0a1bdd6cc90e05dfa9c4104f12f175c')
//            ->setPushInfo(function (PushInfo $pushInfo) {
//                $pushInfo->setTitle('测试标题');
//                $pushInfo->setBody('测试内容');
//            })
//            ->push();
        //p($ret);

        $igt = app('GeTui')->init($this->config);
        //$push = \xing\push\core\PushFactory::getInstance('GeTui')::init($config);
        $igt->setTitle('测试通知');
        $igt->setBody('测试的通知他');
        //$igt->setLogo('https://gitee.com/uploads/69/144269_jswei.png?1418807117');
        //$igt->setLogoURL('https://gitee.com/uploads/69/144269_jswei.png?1418807117');
        $igt->setExtendedData(['title'=>'a new','content'=>'this is a text']);
        $res = $igt->sendOneAndroid('b0a1bdd6cc90e05dfa9c4104f12f175c');
        p($res->getResult());
    }

}
